from collections.abc import  Iterator, Iterable
isinstance((_*_ for _ in range(20)), Iterator)  # True
isinstance([], Iterator)  # False
isinstance({}, Iterator)  # False

# iter() 可以把一个 Iterable 对象转换成 Iterator


class Class():
    def __init__(self, students):
        self.start = -1
        self.students = students
    def __iter__(self):
        return iter(self.students)

    def __next__(self):
        self.start += 1
        return self.students[self.start]

    def __getitem__(self, item):
        return self.students[item]

c = Class(['dsc', 'sd', 'es'])

print(isinstance(c, Iterable)) # True  因为实现了__iter__方法
print(isinstance(c, Iterator)) # True  因为实现了__next__ 方法

print(c[2]) # 因为实现了__getitem__
print(next(c))
for i in c:
    print(i)